﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using CCWin;
namespace weiqijiance
{
    public partial class TESTSL : Form
    {

        public 控制流程.flowcrtl flowbass = new 控制流程.flowcrtl();
        public string sshebei = "侧滑";
        public mainform m_mainform;
        public string sdetid;
        /// <summary>
        /// 结果变量
        /// </summary>
        public float fcehua;
              
        public Thread t1;
        public string xianshineirong;
        public string xianshijieguo;
        public string businessId;
        public string jylsh;
        public string jyjgbh;
        public string jcxdh;
        public string jycs;
        public string jyxm;
        public bool cbjd = false;//仪表检定


        //零点使用
        public float[,] fZero = new float[10, 10000];
        
        //零点使用
        public float[] fAIDataZero = new float[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//零点漂移值
        //红外取反
        public bool[] bhongwaiqf = new bool[16] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };//红外是否取反
        //红外定位时间
        public int[] ihongwaidwsj = new int[16] { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };//红外定位时间单位毫秒
        /// <summary>
        /// 通道参数 包括检测时间，模拟信号，红外信号及控制信号等
        /// </summary>
        public float fjcsj;//检测时间
      

        public int iSLtdz;//接入模拟信号
        public int iSLHWQ=-1;//接入红外信号前
        public int iSLHWH=-1;//接入红外信号后

        public int iSLDOj;//侧滑回位紧
        public int iSLDOs;//侧滑回位松
        public bool jcxjs = false;//检测线结束标识
        public int xssj = 0;//显示时间
        public string revert = "";

        // /声明INI文件的写操作函数 WritePrivateProfileString()
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;



        public TESTSL(int Width, int Height)
        {
            
            InitializeComponent();
            panel_Width = Width;
            panel_Height = Height;
            //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            x = this.Width;
            y = this.Height;
            setTag(this);
            xinxixianshi.Text = "侧滑检测";
            gettongdao();

        }
        bool bzjddzj = false;
        bool bszxzmj = false;
        public void init()
        {
            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            jcxjs = (objini.ReadValue("侧滑", "检测线结束设备").Trim() == "1") ? true : false;
            int.TryParse(objini.ReadValue("侧滑", "信息显示时间").Trim(), out xssj);

            bzjddzj = objini.ReadValue("侧滑", "只检单独综检").Trim().Contains("是") ? true : false;
            bszxzmj = objini.ReadValue("侧滑", "双转向轴免检").Trim().Contains("是") ? true : false;

        }

        public void start()
        {         
            bianliangchushihua();
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();                       
        }
        /// <summary>
        /// 变量初始化
        /// </summary>
        public void bianliangchushihua()
        {
            fcehua = 0;
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

        }
        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            if (newy <= 0)
            {
                newy = 1;
            }
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件


        public void gettongdao()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            for (int i = 0; i < 10; i++)
            {
                string sgetname = ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname.Contains("侧滑"))
                {
                    iSLtdz = i;
                }
                

            }

            for (int i = 0; i < 16; i++)
            {
                string shongwai = ReadValue("通道设置", string.Format(@"红外{0}", i + 1));
                if (shongwai.Contains("侧滑到位前"))
                {
                    iSLHWQ = i;
                }
                if (shongwai.Contains("侧滑到位后"))
                {
                    iSLHWH = i;
                }
                shongwai = ReadValue("通道设置", string.Format(@"红外定位时间{0}", i + 1));
                int.TryParse(shongwai, out ihongwaidwsj[i]);


                shongwai = ReadValue("通道设置", string.Format(@"红外是否取反{0}", i + 1));
                if (shongwai.Contains("是"))
                {
                    bhongwaiqf[i] = true;
                }
                else
                {
                    bhongwaiqf[i] = false;
                }
            }

            for (int i = 0; i < 8; i++)
            {
                string shongwai = ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("侧滑回位紧"))
                {
                    iSLDOj = i;
                }
                if (shongwai.Contains("侧滑回位松"))
                {
                    iSLDOs = i;
                }
            }
        }

        private delegate void FlushClient();//代理
        private void xianshi()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xinxixianshi.Text = string.Format(@"{0}", xianshineirong);
            }
        }

        private void xianshizuo()
        {
            if (this.gauge_slip.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshizuo);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.gauge_slip.Visible = true;
                this.digitalGauge1.Text =  fcehua.ToString("0.00");
            }
        }
 
        protected void thisclose()
        {
            this.Invoke(new Action(this.Close));  //使用委托关闭该窗体
        }

        public void StratTest()
        {
            if ((!flowbass.bzj && bzjddzj && flowbass.sqz < 2))
                return;

            if (flowbass.sqz > 1 && bszxzmj)
                return;
            if (!flowbass.bJCCH)
            {
                try
                {
                    xianshineirong = string.Format(@"侧滑免检");
                    xianshi();
                    flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                    //if (iSLHWQ > -1)//配置红外后才判断红外定位
                    //{
                    //    m_mainform.WaitEventMJ(iSLHWQ, bhongwaiqf[iSLHWQ], ihongwaidwsj[iSLHWQ]);
                    //}
                    //if (jcxjs)
                    //{
                    //    if (flowbass.LastProcessnew(int.Parse(flowbass.sDetectID)))
                    //    {
                    //        flowbass.sendAJend(flowbass.sDetectID);
                    //    }
                    //}

                    return;
                }
                catch
                { }
                return;
            }

            flowbass.objcarclass.tongdao1 = flowbass.isltongdao.ToString();

            flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "侧滑检测开始", flowbass.sDetectID);
            flowbass.LedWrite(flowbass.sPlate, "驶上侧滑台", 1);
            xianshineirong = string.Format(@"驶上侧滑台");
            xianshi();

            // 红外定位
            while (true)
            {
                if (iSLHWQ > -1)
                {
                    Thread.Sleep(20);
                    if (m_mainform.WaitEventZT(iSLHWQ, bhongwaiqf[iSLHWQ], ihongwaidwsj[iSLHWQ]))
                    {
                        break;
                    }

                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                }
                else
                {
                    break;
                }
            }


            flowbass.LedWrite(flowbass.sPlate, "第1轴开始检测", 1);
            xianshineirong = string.Format(@"第1轴侧滑检测开始");
            xianshi();


            int izs = flowbass.sqz;//前轴数
            float[] fcehuas = new float[] { 0, 0 };
            for (int i = 0; i < izs; i++)
            {
                if (i == 1)
                {
                    flowbass.LedWrite(flowbass.sPlate, "第2轴开始检测", 1);
                    // 红外定位
                    if (iSLHWH > -1)
                    {
                        while (true)
                        {

                            if (flowbass.IsCancle())
                            {
                                return;
                            }
                            Thread.Sleep(10);
                            if (!m_mainform.WaitEventZT(iSLHWH, bhongwaiqf[iSLHWH], ihongwaidwsj[iSLHWH]))
                            {
                                break;
                            }

                            if (flowbass.IsCancle())
                            {
                                return;
                            }
                        }
                    }

                    m_mainform.DAC.LiftTwo(false, (short)(iSLDOj), (short)(iSLDOs));//松开
                }
                //测量数据
                float fcehua1 = 0;
                float maxsl = 0;
                while (true)
                {
                    fcehua1 = m_mainform.DAC.getjsz("侧滑", m_mainform.DAC.fAIData[iSLtdz]) - m_mainform.DAC.getjsz("侧滑", m_mainform.DAC.fAIDataZero[iSLtdz]);
                    fcehua1 = (float)Math.Round(fcehua1, 1);
                    if (Math.Abs(maxsl) < Math.Abs(fcehua1))
                    {
                        maxsl = fcehua1;
                    }
                    fcehua = fcehua1;
                    xianshizuo();
                    Thread.Sleep(10);
                    if (iSLHWH > -1)
                    {
                        if (m_mainform.WaitEventZT(iSLHWH, bhongwaiqf[iSLHWH], ihongwaidwsj[iSLHWH]))
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                }
                fcehuas[i] = maxsl;
                if (izs==2&&i==0)
                {
                    m_mainform.DAC.LiftTwo(true, (short)(iSLDOj), (short)(iSLDOs));
                    Thread.Sleep(500);
                }
            }


            xianshineirong = string.Format(@"侧滑检测完成");
            xianshi();
            flowbass.LedWrite(xianshineirong, "", 1);
            Thread.Sleep(xssj);

            {

                bool bGood = true;
                if (fcehuas[0] < flowbass.STD_SLIPL || fcehuas[0] > flowbass.STD_SLIPH)
                {
                    bGood = false;
                }
                bool bpdsl = true;

                if (izs == 2)
                {
                    if (fcehuas[1] < flowbass.STD_SLIPL || fcehuas[1] > flowbass.STD_SLIPH)
                    {
                        bpdsl = false;
                    }
                    xianshineirong = string.Format(@"第1轴数据{0}", fcehuas[0]);
                    xianshi();
                    flowbass.LedWrite(xianshineirong, bGood ? "合格" : "不合格", 1);
                    Thread.Sleep(xssj);

                    xianshineirong = string.Format(@"第2轴数据{0}", fcehuas[1]);
                    xianshi();
                    flowbass.LedWrite(xianshineirong, bpdsl ? "合格" : "不合格", 1);

                }
                else
                {
                    xianshineirong = string.Format(@"侧滑数据{0}", fcehuas[0]);
                    xianshi();
                    flowbass.LedWrite(xianshineirong, bGood ? "合格" : "不合格", 1);
                }
                xianshizuo();
                Thread.Sleep(xssj);

                if (!bGood || !bpdsl)
                {
                    flowbass.getbuhge(flowbass.sDetectID, "A1");
                }
                else
                {

                    flowbass.sethege(flowbass.sDetectID, "A1");
                }


                if (flowbass.sjcbz.Contains("38900"))
                {
                    string jielun = "";
                    string slip1;

                    if (fcehuas[0] > 0)
                    {
                        slip1 = "+" + fcehuas[0].ToString("0.0");
                    }
                    else
                    {
                        slip1 = fcehuas[0].ToString("0.0");
                    }

                    if (izs == 2)
                    {
                        string slip2;
                        if (fcehuas[1] > 0)
                        {
                            slip2 = "+" + fcehuas[1].ToString("0.0");
                        }
                        else
                        {
                            slip2 = fcehuas[1].ToString("0.0");
                        }
                        jielun = string.Format(@"{0},{1}/{2},{3},{4}/{5}", "转向轮横向侧滑量(m/km)", slip1, slip2, "-5～+5", bGood ? "合格" : "不合格", bpdsl ? "合格" : "不合格");
                        flowbass.AddData_Check(flowbass.sDetectID, "DET_SLIP2", "Detects_SJA", slip2);
                        flowbass.AddData(flowbass.sDetectID, "DET_SLIPJL2", "Detects_SJA", bpdsl ? 1 : 2);

                    }
                    else
                    {
                        jielun = string.Format(@"{0},{1},{2},{3}", "转向轮横向侧滑量(m/km)", slip1, "-5～+5", bGood ? "合格" : "不合格");                   
                    }
                    flowbass.AddData(flowbass.sDetectID, "PD_SLIP", "PD_AJ", jielun);
                    flowbass.AddData_Check(flowbass.sDetectID, "DET_SLIP", "Detects_SJA", slip1);
                    flowbass.AddData(flowbass.sDetectID, "DET_SLIPJL", "Detects_SJA", bGood ? 1 : 2);
                }
                else
                {
                    string jielun = "";
                    jielun = string.Format(@"{0},{1},{2},{3}", "第一转向轮侧滑量(m/km)", fcehuas[0].ToString("0.0"), "-5～+5", bGood ? "合格" : "不合格");
                    flowbass.AddData(flowbass.sDetectID, "PD_SLIPZJ", "PD_ZJ", jielun);
                    flowbass.AddData_Check(flowbass.sDetectID, "DET_SLIP", "Detects_SJA", fcehuas[0].ToString("0.0"));
                    if (izs == 2)
                    {
                        flowbass.AddData(flowbass.sDetectID, "DET_SLIPJL2", "Detects_SJA", bpdsl ? 1 : 2);//项目是否合格
                        flowbass.AddData_Check(flowbass.sDetectID, "DET_SLIP2", "Detects_SJA", fcehuas[1].ToString("0.0"));
                        jielun = string.Format(@"{0},{1},{2},{3}", "第二转向轮侧滑量(m/km)", fcehuas[1].ToString("0.0"), "-5～+5", bpdsl ? "合格" : "不合格");
                        flowbass.AddData(flowbass.sDetectID, "PD_SLIPZJ2", "PD_ZJ", jielun);
                    }
                    else
                    {
                        jielun = string.Format(@"{0},{1},{2},{3}", "转向轮横向侧滑量(m/km)", fcehuas[0].ToString("0.0"), "-5～+5", bGood ? "合格" : "不合格");
                        flowbass.AddData(flowbass.sDetectID, "PD_SLIP", "PD_AJ", jielun);
                    }
                    flowbass.AddData(flowbass.sDetectID, "DET_SLIPJL", "Detects_SJA", bGood ? 1 : 2);
                }
                //安检数据检测数据上传

                model.安检联网.modelA1 objmodellw = new model.安检联网.modelA1();//38900上传部分没写
                objmodellw.chz = fcehuas[0].ToString("0.0");
                objmodellw.chpd = bGood ? "1" : "2";
                objmodellw.chz2   ="";
                objmodellw.chpd2 = "0";
                if (flowbass.sjcbz.Contains("38900") && izs == 2)
                {
                    objmodellw.chz2 = fcehuas[1].ToString("0.0");
                    objmodellw.chpd2 = bpdsl ? "1" : "2";
                }

                flowbass.getProcessfinish(flowbass.sDetectID, "A1");


            }
            flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "侧滑检测结束", flowbass.sDetectID);
            flowbass.Updatejcxhao(flowbass.objcarclass.jcxdh, flowbass.sDetectID);
        }

        public void getlingdian()//获取零点
        {
            for (int i = 0; i < 10; i++)
            {
                fAIDataZero[i] = m_mainform.DAC.fAIData[i];
            }

        }

        public void Thread1()
        {
            try
            {
                StratTest();
                if (jcxjs)
                {
                    flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "检测线完成", flowbass.sDetectID);
                    Thread.Sleep(1000);
                }
                if (flowbass.LastProcessnew(int.Parse(flowbass.sDetectID)) && !flowbass.ifinish)
                {
                    flowbass.LedWrite("正在发送", "联网总结束", 1);
                    string slianwangfanhui = flowbass.objajlwbass.sendAJend(flowbass.jylsh, false, flowbass.bzj);
                    if (!(slianwangfanhui.Length > 0 && slianwangfanhui[0].ToString() == "1"))
                    {
                        flowbass.LedWrite("联网失败", slianwangfanhui, 1);
                    }
                    else
                    {
                        flowbass.LedWrite("发送完成", "", 1);
                        flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "检测线完成", flowbass.sDetectID);
                    }
                    Thread.Sleep(2000);
                }
                if (flowbass.LastProcessnewzj(int.Parse(flowbass.sDetectID)) && (flowbass.bzj || flowbass.bsj))
                {
                    xianshineirong = "检测线完成";
                    flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "检测线完成", flowbass.sDetectID);
                    flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                    flowbass.sethegezj(flowbass.sDetectID);
                    Thread.Sleep(2000);
                }
                flowbass.LedWrite(flowbass.sgongwei, "", 1);
                xianshineirong = flowbass.sgongwei;
                xianshi();
                end();
            }
            catch (Exception ex)
            {
                //错误日记 记录到当天日期下目录中
                if (!(ex is System.Threading.ThreadAbortException))
                {
                    flowbass.LedWrite(flowbass.sPlate, "异常,停止检测", 1);
                    m_mainform.baocunriji("侧滑", ex.Message.ToString());
                    m_mainform.SaveErrorLog("侧滑检测流程", ex.Message.ToString());//problem
                }
            }
        }

        public int panel_Width;
        public int panel_Height;   

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (flowbass.izhuangtai == 2)
                {
                    m_mainform.objyibiaobass.select(flowbass.sshebei);
                    m_mainform.bpanelshow = true;
                    m_mainform.showpanel();
                    flowbass.izhuangtai = 1;

                    flowbass.IsReadyForStart();
                    bianliangchushihua();
                    t1 = new Thread(new ThreadStart(Thread1));
                    t1.Start();
                }


            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("侧滑打开窗体失败", ex.Message.ToString());
                m_mainform.SaveErrorLog("侧滑打开窗体", ex.Message.ToString());//problem

            }
        }
        public void timerstart()
        {
            timer1.Enabled = true;
        }
        public void end()
        {           
            flowbass.izhuangtai = 0;
            flowbass.sendend("E", flowbass.sDetectID);
        }
        private void closeform()
        {
            if (this.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(closeform);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.Dispose();
                this.Close();
            }
        }

        private void 仪表设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            工位配置.SLsetting obj = new 工位配置.SLsetting();
            obj.ShowDialog();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                m_mainform.sethongwai(lblhongwai1, m_mainform.WaitEventZT(iSLHWQ, bhongwaiqf[iSLHWQ], ihongwaidwsj[iSLHWQ]));
                m_mainform.sethongwai(lblhongwai2, m_mainform.WaitEventZT(iSLHWH, bhongwaiqf[iSLHWH], ihongwaidwsj[iSLHWH]));
                m_mainform.sethongwai(toolStripLabel2, m_mainform.WaitEventZT(iSLHWQ, bhongwaiqf[iSLHWQ], ihongwaidwsj[iSLHWQ]));
                m_mainform.sethongwai(toolStripLabel4, m_mainform.WaitEventZT(iSLHWH, bhongwaiqf[iSLHWH], ihongwaidwsj[iSLHWH]));
                if (cbjd)
                {
                    Thread.Sleep(10);
                    float fcehua1 = 0;
                    fcehua1 = m_mainform.DAC.getjsz("侧滑", m_mainform.DAC.fAIData[iSLtdz]) - m_mainform.DAC.getjsz("侧滑", m_mainform.DAC.fAIDataZero[iSLtdz]);
                    fcehua = fcehua1;
                    xianshizuo();
                    flowbass.LedWrite("侧滑", string.Format("{0}", fcehua.ToString("0.0")), 1);

                }
            }
            catch
            { }
            try
            {
                if (cbjd)
                {
                    Thread.Sleep(10);
                    float fcehua1 = 0;
                    fcehua1 = m_mainform.DAC.getjsz("侧滑", m_mainform.DAC.fAIData[iSLtdz]) - m_mainform.DAC.getjsz("侧滑", m_mainform.DAC.fAIDataZero[iSLtdz]);
                    fcehua = fcehua1;
                    xianshizuo();
                    flowbass.LedWrite("侧滑", string.Format("{0}", fcehua.ToString("0.0")), 1);

                }
            }
            catch
            { }
        }

        private void but_alone_Click(object sender, EventArgs e)
        {
            start();
        }

        private void but_return_open_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.LiftTwo(true, (short)(iSLDOj), (short)(iSLDOs));
        }

        private void but_return_close_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.LiftTwo(false, (short)(iSLDOj), (short)(iSLDOs));
        }

        private void but_close_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowControls(true);
            ShowButtons(true);
        }

        public void ShowControls(bool flag)
        {
            lblhongwai1.Visible = flag;
            lblhongwai2.Visible = flag;
            label1.Visible = flag;
            gauge_slip.Visible = flag;
        }

        public void ShowButtons(bool flag)
        {
            but_alone.Visible = flag;
            but_return_open.Visible = flag;
            but_return_close.Visible = flag;
            but_tiaoling.Visible = flag;
        }

        private void 设计检定ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            xinxixianshi.Text = "正在检定";
            cbjd = true;
        }

        private void 取消检定ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            xinxixianshi.Text = "侧滑检测";
            cbjd = false;
            flowbass.LedWrite(flowbass.sgongwei, "", 1);
        }

        private void but_tiaoling_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.tiaoling(1);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            start();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.LiftTwo(true, (short)(iSLDOj), (short)(iSLDOs));
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.LiftTwo(false, (short)(iSLDOj), (short)(iSLDOs));
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.tiaoling(1);
        }

        private void TESTSL_Shown(object sender, EventArgs e)
        {
            try
            {
                float newx = (this.Width) / x;
                float newy = (this.Height) / y;
                setControls(newx, newy, this);
                //  ShowControls(false);
                ShowButtons(false);
                this.BackgroundImage = Image.FromFile(@"./ico/侧滑背景.jpg");
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("侧滑Load失败", ex.Message.ToString());//problem
                m_mainform.SaveErrorLog("侧滑Load失败", ex.Message.ToString());//problem
            }
        }
    }
}
